/* Aleksey Matyushev
 *
 * This program is the sole property of Aleksey
 * Matyushev. This program is designed to be a GUI
 * add-on to DATCOM with extended capabilities in
 * providing XML data for FlightGear.
 */

package datcom2;

import java.util.ArrayList;
import org.jdesktop.application.FrameView;

public class TERMINATION extends javax.swing.JPanel {

    public TERMINATION(String path, String name, VTPLNF vtplnfPanel, MAIN mainClass) {
        initComponents();
        caseID = name;
        workingPath = path;
        this.vtplnfPanel = vtplnfPanel;
        this.mainClass = mainClass;
    }

    public void setVTPLNFinput(ArrayList FLTCON, ArrayList OPTINS, ArrayList SYNTHS, String BODY, ArrayList WGPLNF, ArrayList HTPLNF, ArrayList VTPLNF){
        System.out.println("ARRAY LIST's STORED IN TERMINATION");

        this.FLTCON = FLTCON;
        System.out.println("The FLTCON ARRAYLIST is: " + FLTCON.toString());

        this.OPTINS = OPTINS;
        System.out.println("The OPTINS ARRAYLIST is: " + OPTINS.toString());

        this.SYNTHS = SYNTHS;
        System.out.println("The SYNTHS ARRAYLIST is: " + SYNTHS.toString());

        this.BODY = BODY;
        System.out.println("The BODY TextInput is: " + BODY);

        this.WGPLNF = WGPLNF;
        System.out.println("The WGPLNF ARRAYLIST is: " + WGPLNF.toString());
        
        this.HTPLNF = HTPLNF;
        System.out.println("The HTPLNF ARRAYLIST is: " + HTPLNF.toString());
        
        this.VTPLNF = VTPLNF;
        System.out.println("The VTPLNF ARRAYLIST is: " + VTPLNF.toString());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(datcom2.DATCOM2App.class).getContext().getResourceMap(TERMINATION.class);
        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setToolTipText(resourceMap.getString("jLabel1.toolTipText")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "OFF", "ON" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "OFF", "ON" }));
        jComboBox2.setName("jComboBox2"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(35, 35, 35)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jComboBox1, 0, 85, Short.MAX_VALUE))))
                .addContainerGap(566, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 346, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //If NEXT button is pressed collect and pass along all the input
        getInput();
        terminationPanel = this;

        //make the for005 file
        for005 = makeFor005.createFor005(caseID, FLTCON, OPTINS, SYNTHS, BODY, WGPLNF, HTPLNF, VTPLNF, TERMINATION);
        makeFor005.writeFile(workingPath, "for005.dat", for005);
        for005Panel = new for005(workingPath + "/for005.dat", workingPath,caseID, terminationPanel, mainClass);

        //switch panels to for005
        setVisible(false);
        mainClass.setComponent(for005Panel);
        for005Panel.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // if the user presses the BACK button, the pervious frame is shown
        setVisible(false);
        vtplnfPanel.setTERMINATION(this);
        vtplnfPanel.setVisible(true);
        mainClass.setComponent(vtplnfPanel);
        //DATCOM2App.getInstance().show(view);
    }//GEN-LAST:event_jButton2ActionPerformed

    public void getInput(){
        //if the input is ON then store the corresponding TERMINATINO
        //command.
        TERMINATION = new ArrayList<String>();
        if (jComboBox1.getSelectedItem().equals("ON"))
        {
            BUILD = "BUILD";
            TERMINATION.add(BUILD);
        } 
        if (jComboBox2.getSelectedItem().equals("ON"))
        {
            PLOT = "PLOT";
            TERMINATION.add(PLOT);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables

    private ArrayList<String> SYNTHS;
    private ArrayList<String> OPTINS;
    private ArrayList<String> FLTCON;
    private String BODY;
    private ArrayList<String> WGPLNF;
    private ArrayList<String> HTPLNF;
    private ArrayList<String> VTPLNF;

    private String for005;
    private String workingPath;
    private String caseID;
    private String BUILD;
    private String PLOT;

    private ArrayList<String> TERMINATION;

    private getFor005 makeFor005 = new getFor005();
    private for005 for005Panel;

    private VTPLNF vtplnfPanel;
    private TERMINATION terminationPanel;
    private MAIN mainClass;
}
